 import * as type from './type'
 import http from 'utils/http'


 const actionCreators = {

    getBarLists () {

        return async dispatch =>{
         const res =  await http({
                // url:'/index/requestDelegate',
                // params:{
                //     url: 'http://mobile.jumei.com/msapi/mall/allcategories.json'
                // }
                url:'/home/barlists/barlists.json'
            })

          const action = {
              type:type.GETBARLISTS,
              payload: res.data.data 
          }
         
          dispatch(  action )  
        }
    },
    getHomeLists (id) {
        return async dispatch => 
         {
         const res = await http({
            url:'/home/index/indexlist/index'+id+'.json'
        })

        const action = {
            type:type.GETHOMELISTS,
            payload: res.data.item_list 
        }
        // console.log( res.data.item_list )
        dispatch( action )
    }
    },


    getMoreHomeLists (id) {
        return async dispatch => {

            const res = await http({
                url:'/home/index/indexlist/index'+id+'.json'
            })

            const action = {
                type:type.GETMOREHOMELISTS,
                payload: res.data.item_list
            }
            // console.log(res.data.item_list)

            dispatch( action )
        }
    },
    getMoreLuxury (id) {
        return async dispatch => {

            const res = await http({
                url:'/home/index/luxury/list'+id+'.json'
            })

            const action = {
                type:type.GETMORELUXURY,
                payload: res.data.item_list
            }
            // console.log(res.data.item_list)

            dispatch( action )
        }
    },

    getMonAndBabyBanner () {
        return async dispatch => {
            const res = await http({
                url:'/home/monandbaby/banner.json'
            })

            const action = {
                type:type.GETMONANDBABYBANNER,
                payload:res.data
            }

            dispatch(  action )
        }
    },

    getMonAndBabyLists () {
        return async dispatch => {
            const res = await http({
                url:'/home/monandbaby/lists.json'
            })

            // console.log( res.data.item_list )
            const action = {
                type:type.GETMONANDBABYLISTS,
                payload:res.data.item_list
            }

            dispatch( action )
        }
    },
    getBabyDetailLists () {
        return async dispatch => {
            const res = await http({
                url:'/home/monandbaby/babydetail.json'
            })

            const action = {
                type:type.GETBABYDETAILLIST,
                payload:res.data.item_list
            }

            dispatch( action )
        }
    },

    getPopLists ( id ) {
        return async dispatch => {

            const res = await http({
                url:'/home/pop/pop'+id+'.json'
            })

            // console.log( res.data.item_list )
            const action = {
                type:type.GETPOPLISTS,
                payload:res.data.item_list
            }

            dispatch ( action )
        }
    },

    getMorePopLists ( id ) {
        return async dispatch => {

            const res = await http({
                url:'/home/pop/pop'+id+'.json'
            })

            // console.log( res.data.item_list )
            const action = {
                type:type.GETMOREPOPLISTS,
                payload:res.data.item_list
            }
            dispatch ( action )
        }
    },

    getSortDetailList (id) {

        return async dispatch => {
            const res = await http({
                url:'/home/sortdetail/sort'+id+'.json'
            })

            // console.log(res.data.data.item_list)
            const action = {
                type:type.GETSORTDETAILLISTS,
                payload:res.data.data.item_list
            }

            dispatch( action )
        }


    },

    getIndexDetailList ( id ) {
       return async dispatch => {
           const res = await http({
               url:'/home/indexdetail/detail'+id+'.json'
           })


           const action = {
               type:type.GETINDEXDETAILISTS,
               payload : res.data.data
           }
           dispatch ( action )
       }
    },
    getIndexDetailPrice ( id ) {
       return async dispatch => {
           const res = await http({
               url:'/home/indexdetail/detailprice'+id+'.json'
           })

          
           const action = {
               type:type.GETINDEXDETAILPRICE,
               payload : res.data.data.result
           }
           dispatch ( action )
       }
    },
    // getLuxuryBanner() {
    // },
    //轻奢页面的banner
    getLuxuryBanner(){
        return async dispatch=>{
            const res = await http({
                url:'/home/index/luxury/banner.json'
            })
            const  action = {
                type:type.GETLUXURYBANNER,
                payload:res.data
            }
            dispatch( action )
        }
    },
    getLuxuryList(){
        return async dispatch=>{
            const res = await http({
                url:'/home/index/luxury/list4.json',
               
            })
            const  action = {
                type:type.GETLUXURYLIST,
                payload:res.data.item_list
            }
            dispatch( action )
        }
    },
    change_title ( val ) { //改变头部标题

        return dispatch => {

            const action = {
                type:type.CHANGERTITLE,
                payload:val
            }
            dispatch(action)

        }
    },
    addShop ( data ) {

        return async dispatch => {
            const res = await http({
                url:'http://47.98.180.155:5000/shopcar',
                method:'POST',
                params:{
                   ...data
                }
            })
            // console.log(res.data.status)
            const action = {
                type:type.ADDSHOP,
                payload:res.data.status
            }

            dispatch( action )
        }

    },
    getShopCarLists () {
        return async dispatch => {
            
            const res = await http({
                url:'http://47.98.180.155:5000/shopcar',
            })

           
          
            const action = {
                type:type.GETSHOPCARLISTS,
                payload:res.data
            }
            dispatch( action )
        }
    },
    deleteShopCarLists (_id) {
        return async dispatch => {
            const res = await http({
                url:'http://47.98.180.155:5000/shopcar',
                method:'DELETE',
                data:{
                    _id
                }
            })
            
            const action = {
                type:type.DELETESHOPCARLISTS,
                payload:res.data
            }
            dispatch( action )
        }
    },
    editShopCarLists (data) {
        return async dispatch => {
            const res = await http({
                // localhost
                url:'http://47.98.180.155:5000/shopcar',
                method:'PUT',
                data:{
                    ...data
                }
            })
            const action ={
                type:type.EDITSHOPCARLISTS,
                payload:res.data
            }
            dispatch ( action )
        }
    }
    

 }


export default actionCreators